package com.ocom.webapi.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ocom.common.constant.SuguanmqUrl;
import com.ocom.common.request.wx.InpayCustomerRequest;
import com.ocom.common.request.wx.InpayCustomerStageStatusRequest;
import com.ocom.common.request.wx.InpayCustomerStatusRequest;
import com.ocom.common.resp.Result;
import com.ocom.security.authentication.YoCiUser;
import com.ocom.security.utils.SecurityUtils;
import com.ocom.webapi.feign.SuguanMqFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class SuguanMqController {
    @Autowired
    private SuguanMqFeignService suguanMqFeignService;

    @PostMapping(SuguanmqUrl.INPAY_CUSTOMER_STAGE_URL)
    public Result inpayStageCustomer(@RequestBody InpayCustomerStageStatusRequest inpayCustomerRequest){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        inpayCustomerRequest.setComId(yoCiUser.getComId());
        if(ObjectUtil.isEmpty(inpayCustomerRequest.getStartTime())){
            inpayCustomerRequest.setStartTime(DateUtil.beginOfDay(new Date()));
        }
        if(ObjectUtil.isEmpty(inpayCustomerRequest.getEndTime())){
            inpayCustomerRequest.setEndTime(DateUtil.endOfDay(new Date()));
        }
        return this.suguanMqFeignService.inpayStageCustomer(inpayCustomerRequest);
    }

    @PostMapping(SuguanmqUrl.INPAY_CUSTOMER_STATUS_URL)
    public Result inpayCustomerStatus(@RequestBody InpayCustomerStatusRequest inpayCustomerStatusRequest){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        inpayCustomerStatusRequest.setComId(yoCiUser.getComId());
        return this.suguanMqFeignService.inpayCustomerStatus(inpayCustomerStatusRequest);
    }

    @PostMapping(SuguanmqUrl.INPAY_CUSTOMER_URL)
    public Result inpayCustomer(@RequestBody InpayCustomerRequest inpayCustomerRequest){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        inpayCustomerRequest.setComId(yoCiUser.getComId());
        inpayCustomerRequest.setSize(10);
        return this.suguanMqFeignService.inpayCustomer(inpayCustomerRequest);
    }
}
